package com.jh.cloud.bus.gui;

import javax.swing.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class GUIEvent {

    public static void main(String[] args) {

        final JFrame frame = new JFrame("简单的 GUI 程序 - Java 事件/监听机制");

        // 添加监听器
        frame.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                System.out.printf("[%s] 事件 : %s\n", Thread.currentThread().getName(), e);
            }
        });

        frame.setBounds(300, 300, 400, 300);
        frame.setVisible(true);

        // 添加窗口监听器
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                frame.dispose();
            }

            @Override
            public void windowClosed(WindowEvent e) {
                System.exit(0);
            }
        });

    }

}
